// pages/file/file1.js
var api = require('../../utils/api.js');

Page({

    /**
     * 页面的初始数据
     */
    data: {
        files:'',
        imgs:'',
        money:'',
        usersee:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that=this;
        this.setData({
            id:options.id
        })

        this.getallfielbyid();
    },


    getallfielbyid(){
        var that=this;
        var id=this.data.id;
        api.post({
            url: 'wxapp/Caseinfo/getallfielbyid',
            data: {id:id,type:3},
            success: data => {
                that.setData({
                    files:data.data.file,
                    imgs:data.data.img,
                    money:data.data.money,
                    usersee:data.data.usersee
                })
            }
        })

    },



    uploadpdf(){

        let that = this;
        var usrl=api.HOST;


        wx.chooseMessageFile({
            count: 1,  //能选择文件的数量
            type: 'file', //能选择文件的类型,我这里只允许上传文件.还有视频,图片,或者都可以
            success(res) { 
                console.log(res.tempFiles);
                let tempFilePaths = res.tempFiles;
         
                wx.uploadFile({
                  filePath: tempFilePaths[0].path,
                  name: 'file',
                  url: usrl+'/api.php?s=portal/index/one',
                  formData:{},
                  success:function(res){
                    var data= JSON.parse(res.data);

                    console.log(data);
                    that.setData({
                      files:data.data.img
                    });
            
                  },
                  fail: function (res) {
                    console.log('上传失败');
                    }
                })
            }

        })
    },
    getimgs(){
        let that = this;
        var usrl=api.HOST;

        wx.chooseImage({
          count: 1,
          sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
          sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
          success: function (res) {
            console.log(res)
      
            // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
            let tempFilePaths = res.tempFilePaths;
         
            wx.uploadFile({
              filePath: tempFilePaths[0],
              name: 'file',
              url: usrl+'/api.php?s=portal/index/one',
              formData:{},
              success:function(res){
                var data= JSON.parse(res.data);
                that.setData({
                  imgs:data.data.img
                });
        
              },
              fail: function (res) {
                console.log('上传失败');
                }
            })
          }
        })
    },

    getmoney(ret){
        console.log(ret);
        this.setData({
            money:ret.detail.value
        })
    },
    getusersee(ret){
        console.log(ret);
        this.setData({
            usersee:ret.detail.value
        })
    },
    submits(){
        var that=this;
        var id=this.data.id;
        var files=this.data.files;
        var imgs=this.data.imgs;
        var money=this.data.money;
        var usersee=this.data.usersee;


        api.post({
            url: 'wxapp/Caseinfo/casesubmits',
            data: {id:id,files:files,imgs:imgs,money:money,usersee:usersee,type:3},
            success: data => {
                wx.showToast({
                  title: data.msg,
                  icon:'none'
                
                })
            }
        })

    }

})